package com.example.wanghao.wangyixinwen.act;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageButton;

import com.example.wanghao.wangyixinwen.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * Created by wanghao on 2016/5/23.
 */
public class DatailActivity extends Activity implements View.OnClickListener {

    @ViewInject(R.id.btn_left)
    private Button btn_left;
    @ViewInject(R.id.imgbtn_left)
    private ImageButton imgbtn_left;
    @ViewInject(R.id.btn_right)
    private ImageButton btn_right;
    @ViewInject(R.id.imgbtn_right)
    private ImageButton imgbtn_right;
    @ViewInject(R.id.news_detail_wv)
    private WebView news_detail_wv;//显示详情
    @ViewInject(R.id.loading_view)
    private View loading_view;//进度圈视图
    private WebSettings mSettings;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_news_detail);

        ViewUtils.inject(this);

        btn_left.setVisibility(View.GONE);
        imgbtn_left.setImageResource(R.drawable.back);
        imgbtn_left.setOnClickListener(this);

        btn_right.setImageResource(R.drawable.icon_share);
        btn_right.setOnClickListener(this);

        imgbtn_right.setImageResource(R.drawable.icon_textsize);
        //展示新闻详情
        imgbtn_right.setOnClickListener(this);

        String url = getIntent().getStringExtra("url");
        //显示新闻详情
        news_detail_wv.loadUrl(url);

        mSettings = news_detail_wv.getSettings();
        news_detail_wv.setWebViewClient(new WebViewClient(){
            //当页面加载之后
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                loading_view.setVisibility(View.INVISIBLE);
            }
            //当页面加载之前
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                loading_view.setVisibility(View.VISIBLE);
            }
        });

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.imgbtn_left://返回
                this.finish();
                break;
            case R.id.btn_right://分享
                break;
            case R.id.imgbtn_right://字体设置
                mSettings.setTextSize(WebSettings.TextSize.LARGEST);
                break;
        }
    }
}
